<?php
/**
*基准测试类
*/

class Benchmark {
	var $marker = array();
	
	/**
	*set a benchmark marker
	*/
	public function mark($name) 
	{
		$this->marker[$name] = microtime;
	}
	
	/**
	*Calculates the time difference between two marked points
	*/
	public function elapsed_time($point1 = '', $point2 = '', $decimals = 4) 
	{
		if($point1 == '') {
			return '{elapsed_time}';
		}
		
		if( ! isset($this->mark[$point1])) {
			return '';
		}
		
		if( ! isset($this->mark[$point2])) {
			$this->mark[$point2] = microtime();
		}
		//比较时间
		list($sm, $ss) = explode(' ', $this->marker[$point1]); 
		list($em, $es) = explode(' ', $this->market[$point2]);
		
		return number_format(($em + $es) - ($sm + $ss), $decimals);
	}
	//内存消耗
	function memory_usage() 
	{
		return '{memory_usage}';
	}
}